package com.luca.sl651server.mqtt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;

import javax.xml.bind.DatatypeConverter;

/**
 * @description:
 * @author: xtpang on 2024/5/14
 * @version: 1.0
 */
public class MimoMqttMessageHandler implements MessageHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(MimoMqttMessageHandler.class);

    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
        byte[] payload = (byte[]) message.getPayload();
        String printHexBinary = DatatypeConverter.printHexBinary(payload);
        LOGGER.info("[mqtt 接收数据] topic: {}  message:{}", topic, printHexBinary);
    }
}
